package reviewAlgorithms.doublePointers;

import java.util.HashSet;
import java.util.Set;

public class ReverseVowel {


    public static void main(String[] args) {
        String str = ".,";
        Set<Character> vowels = new HashSet<>();
        vowels.add('a');
        vowels.add('e');
        vowels.add('i');
        vowels.add('o');
        vowels.add('u');
        vowels.add('A');
        vowels.add('E');
        vowels.add('I');
        vowels.add('O');
        vowels.add('U');
        System.out.println(reverseVowel(str,vowels));
    }

    private static String reverseVowel(String str, Set<Character> vowels) {
        if (str == null || str.length() <= 1){
            return str;
        }
        char[] chars = str.toCharArray();
        int left = 0;
        int right = chars.length - 1;
        while (left < right){
            while (left < chars.length && !vowels.contains(chars[left])){
                left ++;
            }
            while (right > -1 && !vowels.contains(chars[right])){
                right --;
            }
            if (left < right){
                char temp = chars[left];
                chars[left] = chars[right];
                chars[right] = temp;
                left ++;
                right --;
            }
        }
        return new String(chars);
    }
}
